package View


import ControllerView._
import com.trolltech.qt.core.QIODevice.OpenModeFlag
import com.trolltech.qt.core._
import com.trolltech.qt.core.QEasingCurve.Type
import com.trolltech.qt.gui._

/**
 * <h1>Welcome View Controller</h1>
 *
 *
 * @author Dany Morard
 * @version 1.0
 */


class View(var controller: ControllerView, parent: QWidget) extends QWidget(parent) {


  /**
   * Path of the pictures
   */
  protected val PATH_PICTURE = "pictures/"

  /**
   * Path for the style sheet
   */
  protected val PATH_STYLESHEET = "styleSheet/"

  /**
   * Size of the small button (Cancel, okay)
   */
  protected val SMALL_BUTTON_SIZE = new QSize(80, 25)


  /**
   * Size of the Option view
   */
 // protected val OPTION_VIEW_SIZE = new QRect(40, 85, 700, 450) //420
   protected val OPTION_VIEW_SIZE = new QRect(40, 85, 620, 380) //420


  /**
   * Size of the tools view
   */
  protected val TOOLS_VIEW_SIZE = new QRect (40,50,620,420);

  /**
   * Size of the container
   */
  protected val CONTAINER_SIZE = new QRect(0, 0, 620, 380)


  /**
   * Name that is used in style sheet for the small button
   */
  protected val CSS_SMALL_BUTTON = "buttonCancelOkay"


  /**
   * Name that is used in style sheet for the button browse
   */
  protected val CSS_BROWSE_BUTTON = "buttonBrowse"


  /**
   * Size button browser
   */
  protected val SIZE_BUTTON_BROWSE = new QSize(70,24)


  /**
   * Duration of the animation (ms)
   */
  protected val DURATION_ANIMATION_SLIDE: Int = 300

  /**
   * Lenght of the textEdit
   */
  protected val WIDTH_TEXTEDIT = 400

  var android = new QLabel(this)
  android.setPixmap(new QPixmap(PATH_PICTURE + "bugdroid_3D.png"))
  android.setGeometry(520,263,127,168)
  android.show


  /**
   *
   */
  var container = new QWidget(this)


  /**
   * Object used for creating the slide animation
   */
  protected var animationSlide = new QPropertyAnimation(container, new QByteArray("geometry"))




  this.init


  /**
   * Initialize View
   */
  protected def init {


    // add the style sheet to the window
    this.setStyleSheet(readStyleSheet(PATH_STYLESHEET + "welcomeView.css"))

    // size of the container
    container.setGeometry(CONTAINER_SIZE)


    if (controller.isInstanceOf[ControllerCreateProjectView]) {

      animationSlide.finished.connect(controller, "endAnimationSlide()")
    }
  }


  /**
   * Read and add the style sheet to the window (*.css)
   */
  protected def readStyleSheet(path: String): String = {

    var styleFile = new QFile(path)

    if (!styleFile.open(OpenModeFlag.ReadOnly))
      println("error !!")

    var styleSheet = styleFile.readAll.toString

    styleFile.close()

    styleSheet
  }


  /**
   *
   */
  def animationViewSlide(xStartAnimation: Int, xEndAnimation: Int) {

    // move slide
    animationSlide.setStartValue(new QRect(xStartAnimation, container.pos.y, container.width, container.height))
    animationSlide.setEndValue((new QRect(xEndAnimation, container.pos.y, container.width, container.height)))
    animationSlide.setDuration(DURATION_ANIMATION_SLIDE)
    animationSlide.setEasingCurve(new QEasingCurve(Type.InOutQuint))
    animationSlide.start

  }


}